<?php
/**
 * @version		0.2.0 joomla zmluvy $
 * @package		com_zjmluvy
 * @copyright	Copyright © 2011 - All rights reserved.
 * @license		GNU/GPL
 * @author    AdrianKo		
 * @website   http://code.google.com/p/joomla-zmluvy
 *
 *
 *1.3.2012
 */

// no direct access
defined('_JEXEC') or die('Restricted access');

jimport( 'joomla.application.component.view' );

class jzmluvyViewKategorie extends Jview
{
	function display($tpl = null)
  {
    global $mainframe, $option;
    
		$db				=& JFactory::getDBO();
		$user 		= & JFactory::getUser();
		$context = 'com_jzmluvykategorie.list.';

    $limit		= $mainframe->getUserStateFromRequest( 'global.list.limit', 'limit', $mainframe->getCfg('list_limit'), 'int' );
		$limitstart = $mainframe->getUserStateFromRequest( $context.'limitstart', 'limitstart', 0, 'int' );
    
    $filter_order		= $mainframe->getUserStateFromRequest( $context.'filter_order',		'filter_order',		'title',	'cmd' );
		$filter_order_Dir	= $mainframe->getUserStateFromRequest( $context.'filter_order_Dir',	'filter_order_Dir',	'ASC',			'word' );

    // nahratie submenu
    require (JPATH_COMPONENT_ADMINISTRATOR.DS.'admin.submenu.php');
		
		$orderby = ' ORDER BY '. $filter_order .' '. $filter_order_Dir;
		
		$query = 'SELECT COUNT(id)'
		. ' FROM #__jzmluvy_kategorie'
		;
		$db->setQuery( $query );
		$total = $db->loadResult();
    
    jimport('joomla.html.pagination');
		$pagination = new JPagination( $total, $limitstart, $limit );
		
		$query = 'SELECT *'
			. ' FROM #__jzmluvy_kategorie'
			. $orderby
		;

		$db->setQuery( $query, $pagination->limitstart, $pagination->limit );
		$rows = $db->loadObjectList();
		
		// table ordering
		$lists['order_Dir']	= $filter_order_Dir;
		$lists['order']		= $filter_order;
		
		$this->assignRef('items',		$rows);
		$this->assignRef('lists',		$lists);
		$this->assignRef('pagination',	$pagination);

		parent::display($tpl);

	}

  function pocetzaznamu($catid) {
    $db				=& JFactory::getDBO();
		
		$query = 'SELECT COUNT(id)'
		  . ' FROM #__jzmluvy'
		  . ' WHERE state = 0 AND catid = '.$catid
		;

		$db->setQuery( $query );
		$total_akt = $db->loadResult();
		
    $query = 'SELECT COUNT(id)'
		  . ' FROM #__jzmluvy'
		  . ' WHERE state = -1 AND catid = '.$catid
		;

		$db->setQuery( $query );
		$total_arch = $db->loadResult();
		
		// return '<span title="Aktivní záznamy">'.$total_akt.'</span>/<span title="Archivované záznamy">'.$total_arch.'</span>' ;
    return '<span title="POCET_ZAZNAMOV">'.$total_akt.'</span>' ;  
  }
}
?>